
//var ClueGrid = '080000094004050300000740081920600000006504900000009067450037000009060800860000050';
var ClueGrid = '480300000000000071020000000705000060000200800000000000001076000300000400000050000';

var fso = new ActiveXObject('Scripting.FileSystemObject');
eval(fso.OpenTextFile('BitwiseExtensions.js', 1).ReadAll());
eval(fso.OpenTextFile('DancingLinks.js', 1).ReadAll());
eval(fso.OpenTextFile('SudokuClass.js', 1).ReadAll());
eval(fso.OpenTextFile('SudokuTechniqueExactCover.js', 1).ReadAll());
eval(fso.OpenTextFile('yuxConsole.js', 1).ReadAll());

yux.console.init();

function Solver(func)
{
	var SolutionGrid = new SudokuGrid(ClueGrid);
	SolutionGrid.populateNotations();

	if (SolutionGrid.dataCount < 15) // Minimum number of clues for a unique solution grid currently is 17. 
	{
		WScript.Echo('Insufficent clues provided.');
		return;
	}

	var origCount = SolutionGrid.candidateCount();

	var start = new Date();
	SolutionGrid = func(SolutionGrid);

	var finish = new Date();
	var duration = finish.getTime() - start.getTime();

	console.log('Solver runtime: '+ duration +'ms');

	var newCount = SolutionGrid.candidateCount();
	console.log(origCount + '->' + newCount);

	console.log((new SudokuGrid(ClueGrid)).toLocaleString());
	WScript.Echo(SolutionGrid.toLocaleString()); 
}

// This solver handler uses through Exact Cover technique
function ExactCoverHandler(SolutionGrid)
{
	var DLXGrid = new SudokuDLX(SolutionGrid);
	var result = DLXGrid.solve();

	result.populateNotations();
	return result;
}

Solver(ExactCoverHandler);
